from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from Func_Extract_Data import Extract_Coordinates_3
from Func_List_Files import list_csv_files_3
import matplotlib.lines as mlines
import matplotlib.pyplot as plt
import numpy as np
import math
import os

#----------------------------------------------------------------------------------------------

plt.rcParams.update({
    "text.usetex": True,
    "font.family": "sans-serif",
    "font.sans-serif": ["Helvetica"]})
# for Palatino and other serif fonts use:
plt.rcParams.update({
    "text.usetex": True,
    "font.family": "serif",
    "font.serif": ["Palatino"],
})

#----------------------------------------------------------------------------------------------
Input_Dir   = '.../Post_Processing/Intensity/' # Provide the input directory
HNS         = ['Florence']
HRS         = ['96']
GS          = '8km'
TMS         = ['NoTurb']
CLTS        = ['Default', 'TSKM2', 'TSKP2']

#--------------------------------------------------------------------
fig, ax = plt.subplots(figsize=(16,10))
colors  = ['green', 'royalblue', 'red']
markers = ['^', 'p', 'd']
lines   = ['-', ':', '-.']

#--------------------------------------------------------------------
idx     = 0
for HN in HNS:
    c = 0
    for CLT in CLTS:

        Hurricane_Setting = HN + '_' + HRS[idx] + 'Hours_' + GS + '_' + TMS[0] + '_' + CLT + '.csv'
        print (Hurricane_Setting)
        csv_files = []
        os.chdir(Input_Dir)
        csv_files = list_csv_files_3 (Input_Dir, csv_files)
        csv_files.sort()

        Wind_Speed = []
        Times      = []
        Wind_Speed = Extract_Coordinates_3 ("Real_Output.csv", Wind_Speed, 'Real_Wnd_Ints')
        label      = 'Best Track'
        for i in range (len(Wind_Speed)):
            Times.append(i*6)
        ax.plot(Times[0: len(Wind_Speed)], Wind_Speed, color='black', linewidth=2, label = label)

        Wind_Speed = []
        Times      = []
        Wind_Speed = Extract_Coordinates_3 (Hurricane_Setting, Wind_Speed, 'Intensity')
        for i in range (len(Wind_Speed)):
            Times.append(i*6)
        ax.plot(Times[0: len(Wind_Speed)], Wind_Speed, color=colors[c], linewidth=2, linestyle=lines[c],marker=markers[c] )# label = label)
        ax.set_yticks(np.arange(30, math.ceil(np.max(Wind_Speed)/10)*10+10, 10.0))
        ax.xaxis.set_minor_locator(MultipleLocator(4))
        ax.yaxis.set_minor_locator(MultipleLocator(1))   

        ax.tick_params(which="major", axis="x", direction="in", labelsize=14)
        ax.tick_params(which="minor", axis="x", direction="in", labelsize=14)
        ax.tick_params(which="major", axis="y", direction="in", labelsize=14)
        ax.tick_params(which="minor", axis="y", direction="in", labelsize=14)   
        
        ax.set_title(HN, {'size': 16})      
        ax.set_ylabel("Intensity" + " [m s" + r"$^{-1}$" + ']', fontsize=16)
        ax.set_xlabel("Time [hr]", fontsize=16)    
        c += 1
    idx += 1                    

#--------------------------------------------------------------------
black_line = mlines.Line2D([], [], color='black', marker= 'o', markersize=5)
royalblue_line = mlines.Line2D([], [], color='royalblue', linestyle=':', marker= 'p', markersize=5)
red_line = mlines.Line2D([], [], color='red', linestyle='-.', marker= 'd', markersize=5)
green_line = mlines.Line2D([], [], color='green', linestyle='-', marker= '^', markersize=5)

fig.legend(handles = [red_line, green_line, royalblue_line, black_line], 
labels=['$\mathit{TSK}$'+r'$_{+ 2K}$', '$\mathit{Default}$', '$\mathit{TSK}$'+r'$_{- 2K}$', "Best Track"],
bbox_to_anchor=(0.7, 0.99, -0.4, 0), loc = 'upper center', frameon = False,
mode='expand', ncol = 4, fontsize='xx-large')

plt.show()
